// store/index.js
import Vue from 'vue'
import Vuex from 'vuex'
import user from './modules/user'

Vue.use(Vuex)

export default new Vuex.Store({
    modules: {
        user
    },
    state: {
        selectMenu: [],
        token: null
    },
    mutations: {
        addMenu(state, payload) {
            if (state.selectMenu.findIndex(item => item.path === payload.path) === -1) {
                state.selectMenu.push(payload);
            }
        },
        closeMenu(state, payload) {
            // 找到点击数据的索引，然后删除
            const index = state.selectMenu.findIndex(item => item.name === payload.name);
            state.selectMenu.splice(index, 1);
        },
    },
});
